{%  extends 'base.html' %}
{% block title %}
    <a class="navbar-brand" href="#"> 部门信息 </a>
{% endblock %}

{% block write %}
    {% if current_user.has_role('Admin') or current_user.has_role('Root') %}
    <li>
    <a href="{{ url_for('department_add') }}" class="btn btn-simple btn-info btn-icon like" data-toggle="dropdown">
        添加部门
    </a>
    </li>
    {% endif %}
{% endblock %}

{% block content %}
        <div class="content">
        <h4 class="title">部门信息</h4>
        <div class="toolbar">

            <!--        Here you can write extra buttons/actions for the toolbar              -->
            <form method="post">
                查询方式
                <select name="info" required>
                    <option value="departmentID">部门编号</option>
                    <option value="departmentname">部门名称</option>
                    <option value="departmentphone">电话</option>
                </select>
                <input type="text" name="date" autocomplete="off" required>
                <input type="submit" name="submit" value="查询">
            </form>

        </div>
        {% if info == 'departmentID' or info == 'departmentname' or info == 'departmentphone'%}
            <div class="material-datatables">
                <table id="datatables" class="table table-striped table-no-bordered table-hover"
                       style="width:100%;cellspacing:0">
                    <thead>
                    <tr>
						<th>部门编号</th>
                        <th>部门名称</th>
                        <th>类型</th>
                        <th>电话</th>
                        <th>传真</th>
						<th>描述</th>
						<th>上级部门</th>
						<th>成立时间</th>
                        <th class="disabled-sorting">操作</th>
                    </tr>
                    </thead>

                    <tbody>
                    <tr>
                        <td>{{ departments.departmentID }}</td>
                        <td>{{ departments.departmentname }}</td>
                        <td>{{ departments.departmenttype }}</td>
                        <td>{{ departments.departmentphone }}</td>
						{% if departments.departmentfax == None  %}
                        <td></td>
                        {% else %}
                        <td>{{ departments.departmentfax }}</td>
                        {% endif %}
						<td>{{ departments.describe }}</td>
						<td>{{ departments.superior }}</td>
						<td>{{ departments.establish }}</td>
                        {% if current_user.has_role('Admin') or current_user.has_role('Root') %}
                        <td>
                            <form  method="post" action="{{ url_for('department_delete',departmentID=departments.departmentID) }}">
                                <a href="{{ url_for('department_alter',departmentID=departments.departmentID) }}"
                                   class="btn btn-simple btn-info btn-icon like">修改</a>
                                <input name="delete" type="submit" value="删除" onclick="return confirm('确认删除此部门？')" class="btn btn-simple btn-danger btn-icon remove">
                            </form>
                        </td>
                        {% endif %}
                    </tr>
                    </tbody>

                </table>
            </div>
        {% else %}

                <div class="material-datatables">
                    <table id="datatables" class="table table-striped table-no-bordered table-hover"
                           style="width:100%;cellspacing:0">
                        <thead>
                        <tr>
                            <th>部门编号</th>
							<th>部门名称</th>
							<th>类型</th>
							<th>电话</th>
							<th>传真</th>
							<th>描述</th>
							<th>上级部门</th>
							<th>成立时间</th>
                            <th class="disabled-sorting">操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        {% for department in departments %}
                        <tr>
                            <td>{{ department.departmentID }}</td>
                            <td>{{ department.departmentname }}</td>
							<td>{{ department.departmenttype }}</td>
							<td>{{ department.departmentphone }}</td>
                            {% if department.departmentfax == None  %}
                            <td></td>
                            {% else %}
							<td>{{ department.departmentfax }}</td>
                            {% endif %}
							<td>{{ department.describe }}</td>
							<td>{{ department.superior }}</td>
							<td>{{ department.establish }}</td>

							{% if current_user.has_role('Admin') or current_user.has_role('Root') %}
                            <td>
                            <form  method="post" action="{{ url_for('department_delete',departmentID=department.departmentID) }}">
                                <a href="{{ url_for('department_alter',departmentID=department.departmentID) }}"
                                   class="btn btn-simple btn-info btn-icon like">修改</a>
                                <input name="delete" type="submit" value="删除" onclick="return confirm('确认删除此部门？')" class="btn btn-simple btn-danger btn-icon remove">
                            </form>
                            </td>
							{% endif %}
                        </tr>
                        {% endfor %}
                        </tbody>

                    </table>
                </div>


        {% endif %}
    </div>
{% endblock %}